#pragma once

#include <vector>
#include <map>

#include "BankData.h"

#include "ParticipantExecutor.h"

namespace PC2
{

class PC2DataStore;

class BankAccountStoreExecutor
	: public ParticipantExecutor
{
public:
	BankAccountStoreExecutor(std::string const& aName, PC2DataStore* apStore);
	virtual ~BankAccountStoreExecutor();

public:
	void DumpAllAcount(std::vector<BankAccount>* apVec);
	void SetAccountValueAndStore(std::string const& aName, uint32_t aValue);

public:
	bool Prepare( uint32_t aTransId, char const* apData, uint32_t aSize, leveldb::WriteBatch* apBatch );
	void Commit( uint32_t aTransId, char const* apData, uint32_t aSize, leveldb::WriteBatch* apBatch );
	void Abort( uint32_t aTransId, char const* apData, uint32_t aSize, leveldb::WriteBatch* apBatch );

protected:
	void ReloadAllAccounts();

protected:
	void StringIDToAccount(std::string* apKey, BankAccount* apAccount);
	std::string AccountToStringID(BankAccount* apAccount);
	std::string AccountToStringID(char const* apName);

protected:
	std::string m_Name;
	PC2DataStore* m_pStore;
	std::map<std::string, BankAccount> m_AccountMap;
};



}